package cn.wolfcode.trip.app.controller;


import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.TravelQueryObject;
import cn.wolfcode.trip.base.service.IRegionService;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户资源控制器
 */
@RestController
@RequestMapping("/travels")
public class TravelController {
    @Autowired
    private ITravelService travelService;

    @PostMapping
    public JSONResult save(Travel travel){
        travelService.saveOrUpdate(travel);
        return new JSONResult();
    }
    @PutMapping("{id}")
    public JSONResult update(Travel travel){
        travelService.saveOrUpdate(travel);
        return new JSONResult();
    }
    @GetMapping("{id}")
    public Travel getById(@PathVariable Long id){
        Travel travel = travelService.selectById(id);
        return travel;
    }
    @GetMapping
    public PageInfo listAll(TravelQueryObject qo){
        qo.setOrderBy("t.releaseTime desc");
        qo.setState(Travel.STATE_RELEASE);
        PageInfo<Travel> list = travelService.list(qo);
        return list;
    }


}
